
#include "stdafx.h"
#include "rest.h"
#include "encode.h"


PreLogin::PreLogin()
{
	m_returncode = 0;
	m_returnmessage = "";
	m_imagefile = "";
}

int PreLogin::ParseJson(string &strJson)
{
	Json::Value root;
	Json::Reader reader;
	if (!reader.parse(strJson, root)) {
		return -1;
	}
	JSON_GET_INT(root, m_returncode, "return_code");

	if (m_returncode != 0)
		return 0;

	JSON_GET_STRING(root, m_returnmessage, "return_message");

	Json::Value json_tmp = root["data"];															
	JSON_GET_STRING(json_tmp, m_imagefile, "image_file");

	return 0;
}


UserLogin::UserLogin()
{
	m_username = "";
	m_userpwd = "";
	m_door = "";
	m_returncode = 0;
	m_returnmessage = "";
	//m_imagefile = "";
}

string UserLogin::ToJson()
{
	string tmp = "userName="+UrlEncode(m_username)+"&userPwd="+UrlEncode(m_userpwd)+"&door="+UrlEncode(m_door);

	return tmp;
	Json::Value root;
	root["userName"] = m_username;
	root["userPwd"] = m_userpwd;
	root["door"] = m_door;

	Json::FastWriter writer;
	return writer.write(root);
}

int UserLogin::ParseJson(string &strJson)
{
	Json::Value root;
	Json::Reader reader;
	if (!reader.parse(strJson, root)) {
		return -1;
	}
	JSON_GET_INT(root, m_returncode, "return_code");

	if (m_returncode != 0)
		return 0;

	JSON_GET_STRING(root, m_returnmessage, "return_message");

	//Json::Value json_tmp = root["data"];															
	//JSON_GET_STRING(json_tmp, m_imagefile, "image_file");

	return 0;
}
